package com.hotline.monitor.service.agent;

import com.alibaba.fastjson.JSONArray;
import com.hotline.monitor.util.HttpUtils;
import com.hotline.monitor.util.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.util.Collections;
import java.util.List;

/**
 * <p>
 * 坐席事件service实现类
 * </p>
 *
 * @author yeshengqi
 * @since 2023-08-19 15:23
 */
@Service
@Slf4j
public class AgentEventServiceImpl implements AgentEventService{

    private static final String URI_GET_TIMEOUT_AGENT_EVENT = "/agent/event/get-timeout-agent";


    private static final String URI_DELETE_TIMEOUT_AGENT_EVENT = "/agent/event/delete-timeout-agent/{}";

    @Value("${hotline.url}")
    private String url;

    @Override
    public List<String> getTimeoutAgentList() {
        try{
            String reqUrl = url + URI_GET_TIMEOUT_AGENT_EVENT;
            String resultString = HttpUtils.doGet(reqUrl);
            List<String> list = JSONArray.parseArray(resultString,String.class);
            return list;
        }catch (Exception e){
            log.error("坐席超时请求失败：{}",e);
        }
        return Collections.EMPTY_LIST;
    }

    @Override
    public void deleteTimeoutAgent(String workNo) {
        try{
            String reqUrl = url + URI_DELETE_TIMEOUT_AGENT_EVENT;
            reqUrl = StringUtils.format(reqUrl,workNo);
            HttpUtils.doPost(reqUrl);
        }catch (Exception e){
            log.error("删除超时坐席请求失败：{}",e);
        }
    }
}
